| Total Complexity | 3 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { |
||
| 23 | |||
| 24 | @Controller('app/tasks/edit') |
||
| 25 | @UseGuards(IsAuthenticatedGuard) |
||
| 26 | export class EditTaskController { |
||
| 27 | constructor( |
||
| 28 | @Inject('ICommandBus') |
||
| 29 | private readonly commandBus: ICommandBus, |
||
| 30 | @Inject('IQueryBus') |
||
| 31 | private readonly queryBus: IQueryBus, |
||
| 32 | private readonly resolver: RouteNameResolver |
||
| 33 | ) {} |
||
| 34 | |||
| 35 | @Get(':id') |
||
| 36 | @WithName('crm_tasks_edit') |
||
| 37 | @Render('pages/tasks/edit.njk') |
||
| 38 | public async get(@Param() idDto: IdDTO) { |
||
| 39 | const task = await this.queryBus.execute(new GetTaskByIdQuery(idDto.id)); |
||
| 40 | |||
| 41 | return { |
||
| 42 | task |
||
| 43 | }; |
||
| 44 | } |
||
| 45 | |||
| 46 | @Post(':id') |
||
| 47 | public async post( |
||
| 48 | @Param() idDto: IdDTO, |
||
| 49 | @Body() dto: TaskDTO, |
||
| 50 | @Res() res: Response |
||
| 51 | ) { |
||
| 52 | const { name } = dto; |
||
| 53 | |||
| 54 | try { |
||
| 55 | await this.commandBus.execute(new UpdateTaskCommand(idDto.id, name)); |
||
| 56 | |||
| 57 | res.redirect(303, this.resolver.resolve('crm_tasks_list')); |
||
| 58 | } catch (e) { |
||
| 59 | throw new BadRequestException(e.message); |
||
| 60 | } |
||
| 63 |